const jsonServer = require("json-server");
const server = jsonServer.create();
const router = jsonServer.router("./db.json");
const middlewares = jsonServer.defaults();

// Set default middlewares (logger, static, cors and no-cache)
server.use(middlewares);

// Add custom routes before JSON Server router
server.post("/user/login", (req, res) => {

  res.jsonp({uid:111,type:0});
});

server.post('/user/register',(req,res)=>{
  res.jsonp({uid:'111'});
})

server.get('/user/getUserInfo/111',(req,res)=>{
  res.jsonp({id:1,name:'111',sex:'0',type:1,id_number:111111111111111,account_balance:0,avatar:'blob:http://localhost:8080/b61c3910-e59e-4c80-9a8e-32cea5f6915f'})
})

server.post('/user/update',(req,res) =>{
  res.jsonp({uid:'111'})
})

server.post('/user/recharge',(req,res) => {
  res.jsonp({success:'1'})
})

const order = [
  {
    id: "1",
    order_time: "2023-1-1",
    time: "2023-1-4",
    doctor: {
      name: "11123",
      description:
        "不断总结临床经验，将其升华为更为凝练的技能和知识储备。6 科研能力。找到临床上的未被满足的需求，提出假设，构建研究设计，验证假设。7 写作能力。有了好的经验，好的实验结果，要转化为文字发表，这要熟悉杂志社的要求，用规范的格式和语言进行表述。8 自我保护能力。最近李雪健的医疗事故罪让很多",
      img: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
      sex: "",
      outpatient: "发热",
    },
    money: "111",
    status: "0",
    medicineList: [
      {
        id: "11",
        name: "docutor1",
        description: "",
        img: "1",
      },
    ],
  },
  {
    id: "2",
    order_time: "2023-1-1",
    time: "2023-1-5",
    doctor: {
      name: "doctorName",
      description:
        "不断总结临床经验，将其升华为更为凝练的技能和知识储备。6 科研能力。找到临床上的未被满足的需求，提出假设，构建研究设计，验证假设。7 写作能力。有了好的经验，好的实验结果，要转化为文字发表，这要熟悉杂志社的要求，用规范的格式和语言进行表述。8 自我保护能力。最近李雪健的医疗事故罪让很多人担忧。作为下级医生，发生重大问题一定要及时请上级医生会诊，包括医院总值班！医疗文书书写要及时和规范！",
      img: "",
      sex: "",
      outpatient: "发热",
    },
    money: "111",
    status: "0",
    medicineList: [
      {
        id: "11",
        name: "",
        description: "",
        img: "1",
      },
    ],
  },
  {
    id: "3",
    order_time: "2023-1-1",
    time: "2023-1-4",
    doctor: {
      name: "11123",
      description:
        "研究.................................................",
      img: "",
      sex: "",
      outpatient: "发热",
    },
    money: "111",
    status: "3",
    medicineList: [
      {
        id: "11",
        name: "medicines",
        description: "",
        img: "1",
      },
    ],
  },
  {
    id: "4",
    order_time: "2023-1-1",
    time: "2023-1-4",
    doctor: {
      name: "11123",
      description:
        "研究.................................................",
      img: "",
      sex: "",
      outpatient: "发热",
    },
    money: "111",
    status: "1",
    medicineList: [
      {
        id: "11",
        name: "",
        description: "",
        img: "1",
      },
    ],
  },
  {
    id: "5",
    order_time: "2023-1-1",
    time: "2023-1-4",
    doctor: {
      name: "11123",
      description:
        "研究.................................................",
      img: "",
      sex: "",
      outpatient: "发热",
    },
    money: "111",
    status: "2",
    medicineList: [
      // {
      //   id: "11",
      //   name: "",
      //   description: "",
      //   img: "1",
      // },
    ],
  },
]
server.get('/patient/order/111',(req,res) => {
  res.jsonp(order)
})
server.post('/patient/cancel/order/2',(req,res)=>{
  res.jsonp({success:1})
})
// To handle POST, PUT and PATCH you need to use a body-parser
// You can use the one used by JSON Server
server.use(jsonServer.bodyParser);
server.use((req, res, next) => {
  if (req.method === "POST") {
    req.body.createdAt = Date.now();
  }
  // Continue to JSON Server router
  next();
});

// Use default router
server.use(router);
server.listen(3000, () => {
  console.log("JSON Server is running at http://localhost:3000/");
});